/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package project;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *
 * @author jon
 */
public class Lease {
    private int lease_id;
    private int property_id;
    private String associate_name;
    private int associate_address_zipcode;
    private String associate_address_state;
    private String associate_address_city;
    private String associate_address_street;
    private double deposit_amount;
    private Date start_date;
    private Date end_date;
    private int duration;

    public Lease(int lease_id, int property_id, String associate_name, int associate_address_zipcode, String associate_address_state, String associate_address_city, String associate_address_street, double deposit_amount, Date start_date, Date end_date, int duration) {
        this.lease_id = lease_id;
        this.property_id = property_id;
        this.associate_name = associate_name;
        this.associate_address_zipcode = associate_address_zipcode;
        this.associate_address_state = associate_address_state;
        this.associate_address_city = associate_address_city;
        this.associate_address_street = associate_address_street;
        this.deposit_amount = deposit_amount;
        this.start_date = start_date;
        this.end_date = end_date;
        this.duration = duration;
    }

    /**
     * @return the lease_id
     */
    public int getLease_id() {
        return lease_id;
    }

    /**
     * @param lease_id the lease_id to set
     */
    public void setLease_id(int lease_id) {
        this.lease_id = lease_id;
    }

    /**
     * @return the associate_name
     */
    public String getAssociate_name() {
        return associate_name;
    }

    /**
     * @param associate_name the associate_name to set
     */
    public void setAssociate_name(String associate_name) {
        this.associate_name = associate_name;
    }

    /**
     * @return the associate_address_zipcode
     */
    public int getAssociate_address_zipcode() {
        return associate_address_zipcode;
    }

    /**
     * @param associate_address_zipcode the associate_address_zipcode to set
     */
    public void setAssociate_address_zipcode(int associate_address_zipcode) {
        this.associate_address_zipcode = associate_address_zipcode;
    }

    /**
     * @return the associate_address_state
     */
    public String getAssociate_address_state() {
        return associate_address_state;
    }

    /**
     * @param associate_address_state the associate_address_state to set
     */
    public void setAssociate_address_state(String associate_address_state) {
        this.associate_address_state = associate_address_state;
    }

    /**
     * @return the associate_address_city
     */
    public String getAssociate_address_city() {
        return associate_address_city;
    }

    /**
     * @param associate_address_city the associate_address_city to set
     */
    public void setAssociate_address_city(String associate_address_city) {
        this.associate_address_city = associate_address_city;
    }

    /**
     * @return the associate_address_street
     */
    public String getAssociate_address_street() {
        return associate_address_street;
    }

    /**
     * @param associate_address_street the associate_address_street to set
     */
    public void setAssociate_address_street(String associate_address_street) {
        this.associate_address_street = associate_address_street;
    }

    /**
     * @return the deposit_amount
     */
    public double getDeposit_amount() {
        return deposit_amount;
    }

    /**
     * @param deposit_amount the deposit_amount to set
     */
    public void setDeposit_amount(double deposit_amount) {
        this.deposit_amount = deposit_amount;
    }

    /**
     * @return the start_date
     */
    public Date getStart_date() {
        return start_date;
    }

    /**
     * @param start_date the start_date to set
     */
    public void setStart_date(Date start_date) {
        this.start_date = start_date;
    }

    /**
     * @return the end_date
     */
    public Date getEnd_date() {
        return end_date;
    }

    /**
     * @param end_date the end_date to set
     */
    public void setEnd_date(Date end_date) {
        this.end_date = end_date;
    }

    /**
     * @return the duration
     */
    public int getDuration() {
        return duration;
    }

    /**
     * @param duration the duration to set
     */
    public void setDuration(int duration) {
        this.duration = duration;
    }

    /**
     * @return the property_id
     */
    public int getProperty_id() {
        return property_id;
    }

    /**
     * @param property_id the property_id to set
     */
    public void setProperty_id(int property_id) {
        this.property_id = property_id;
    }

    public void insert()
    {
        try
        {
            String host = "jdbc:oracle:thin:@localhost:1521:xe";
            String username = "jon";
            String password = "chaosecco";
            String driverName = "oracle.jdbc.driver.OracleDriver";
            Class.forName(driverName);

            Connection connection = DriverManager.getConnection(host,
                    username, password);
            System.out.print("Connected successfully.");
            String insertQuery = "INSERT INTO LEASE(" +
                    "lease_id, " +
                    "property_number, " +
                    "associate_name, " +
                    "client_address_zipcode, " +
                    "client_address_state, " +
                    "client_address_city, "  +
                    "client_address_street, " +
                    "deposit_amount, " +
                    "start_date, " +
                    "end_date, " +
                    "duration)" +
                    "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
            PreparedStatement ps = connection.prepareStatement(insertQuery);
            ps.setInt(1, lease_id);
            ps.setInt(2, property_id);
            ps.setString(3, associate_name);
            ps.setInt(4, associate_address_zipcode);
            ps.setString(5, associate_address_state);
            ps.setString(6, associate_address_city);
            ps.setString(7, associate_address_street);
            ps.setDouble(8, deposit_amount);
            ps.setDate(9, start_date);
            ps.setDate(10, end_date);
            ps.setInt(11, duration);
            ps.executeUpdate();

            connection.close();
        }

        catch (SQLException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }

        catch(ClassNotFoundException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }
    }
}
